﻿//////////////////////////////////////////////////////////////////
//
// Diamond.cs
//
// Copyright (c) 2012 Dan Pike.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// This is part of an implementation of the algorithm described by
// Mark Duchaineau in his paper: "Realtime Optimal Adaptation for Planetary
// Geometry and Texture: 4-8 Tile Hierarchies" and in similar papers and
// example source code that he has published. Though I have studied it
// carefully and I believe that I understand how it works, all credit
// for the design of the algorithm must be directed to Mark Duchaineau.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utilities;
using System.Threading;

namespace Geometry
{
   public class Diamond
   {
      ////////////////////////////////////////////////////////////////////////
      //
      static Diamond()
      {
      }

      ////////////////////////////////////////////////////////////////////////
      //
      protected Diamond()
      {
      }

      ////////////////////////////////////////////////////////////////////////
      //
      public static Diamond create(int level, Point3D centre)
      {
         Diamond diamond = new Diamond();
         diamond.level = level;
         diamond.centre = centre;
         return diamond;
      }

      ////////////////////////////////////////////////////////////////////////
      // The two parents
      public Diamond p0;
      public Diamond p1;

      ////////////////////////////////////////////////////////////////////////
      // The two ancestors
      public Diamond a0;
      public Diamond a1;

      ////////////////////////////////////////////////////////////////////////
      // The four kids
      public Diamond k0;
      public Diamond k1;
      public Diamond k2;
      public Diamond k3;

      ////////////////////////////////////////////////////////////////////////
      //
      public int level;             // root is level 0, kids are level > 0
      public bool clipped;          // Outside the view area (perhaps outside the whole terrain, if it's part of the base mesh)
      public bool split;            // Is this split?
      public Point3D centre;

      // private Sphere3D bounds_;     // Bounding sphere for frustum calculation
   }
}
